package com.codejoys.monitor.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.codejoys.monitor.Constants;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.Date;

public class DeviceExportData {
    @ColumnWidth(25)
    @ExcelProperty(value = "设备序列号", index = 0)
    private String sn;

    @ColumnWidth(15)
    @ExcelProperty(value = "通道码", index = 1)
    private String channel;

    @ColumnWidth(15)
    @ExcelProperty(value = "老化次数", index = 2)
    private Integer agingTimes;

    @ColumnWidth(15)
    @ExcelProperty(value = "设定电压", index = 3)
    private BigDecimal presetVoltage;

    @ColumnWidth(15)
    @ExcelProperty(value = "设定电流", index = 4)
    private BigDecimal presetCurrent;

    @ColumnWidth(15)
    @ExcelProperty(value = "设定时间", index = 5)
    private Integer presetDuration;

    @ColumnWidth(15)
    @ExcelProperty(value = "电压上限", index = 6)
    private BigDecimal voltageUpper;

    @ColumnWidth(15)
    @ExcelProperty(value = "电压下限", index = 7)
    private BigDecimal voltageLower;

    @ColumnWidth(15)
    @ExcelProperty(value = "电流上限", index = 8)
    private BigDecimal currentUpper;

    @ColumnWidth(15)
    @ExcelProperty(value = "电流下限", index = 9)
    private BigDecimal currentLower;

    @ColumnWidth(25)
    @ExcelProperty(value = "老化开始时间", index = 10)
    private Date agingStartTime;

    @ColumnWidth(25)
    @ExcelProperty(value = "老化停止时间", index = 11)
    private Date agingStopTime;

//    @ColumnWidth(25)
//    @ExcelProperty(value = "老化时长", index = 12)
//    private Date agingDuration;

    @ColumnWidth(25)
    @ExcelProperty(value = "下机时间", index = 12)
    private Date offlineTime;

    @ColumnWidth(15)
    @ExcelProperty(value = "状态", index = 13)
    private String status;

    @ColumnWidth(15)
    @ExcelProperty(value = "老化结果", index = 14)
    private String result;

    @ColumnWidth(25)
    @ExcelProperty(value = "错误码", index = 15)
    private String errorCode;

    @ColumnWidth(25)
    @ExcelProperty(value = "错误消息", index = 16)
    private String errorMessage;

    @ColumnWidth(25)
    @ExcelProperty(value = "错误备注", index = 17)
    private String errorRemark;

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Integer getAgingTimes() {
        return agingTimes;
    }

    public void setAgingTimes(Integer agingTimes) {
        this.agingTimes = agingTimes;
    }

    public Date getAgingStartTime() {
        return agingStartTime;
    }

    public void setAgingStartTime(Date agingStartTime) {
        this.agingStartTime = agingStartTime;
    }

    public Date getAgingStopTime() {
        return agingStopTime;
    }

    public void setAgingStopTime(Date agingStopTime) {
        this.agingStopTime = agingStopTime;
    }

    public Date getOfflineTime() {
        return offlineTime;
    }

    public void setOfflineTime(Date offlineTime) {
        this.offlineTime = offlineTime;
    }

    public BigDecimal getPresetVoltage() {
        return presetVoltage;
    }

    public void setPresetVoltage(BigDecimal presetVoltage) {
        this.presetVoltage = presetVoltage;
    }

    public BigDecimal getPresetCurrent() {
        return presetCurrent;
    }

    public void setPresetCurrent(BigDecimal presetCurrent) {
        this.presetCurrent = presetCurrent;
    }

    public Integer getPresetDuration() {
        return presetDuration;
    }

    public void setPresetDuration(Integer presetDuration) {
        this.presetDuration = presetDuration;
    }

    public BigDecimal getVoltageUpper() {
        return voltageUpper;
    }

    public void setVoltageUpper(BigDecimal voltageUpper) {
        this.voltageUpper = voltageUpper;
    }

    public BigDecimal getVoltageLower() {
        return voltageLower;
    }

    public void setVoltageLower(BigDecimal voltageLower) {
        this.voltageLower = voltageLower;
    }

    public BigDecimal getCurrentUpper() {
        return currentUpper;
    }

    public void setCurrentUpper(BigDecimal currentUpper) {
        this.currentUpper = currentUpper;
    }

    public BigDecimal getCurrentLower() {
        return currentLower;
    }

    public void setCurrentLower(BigDecimal currentLower) {
        this.currentLower = currentLower;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public static DeviceExportData fromDevice(DeviceDto dto) {
        DeviceExportData d = new DeviceExportData();

        d.setSn(dto.getSn());
        d.setChannel(dto.getChannel());
        d.setAgingTimes(dto.getAgingTimes());
        d.setPresetVoltage(dto.getPresetVoltage());
        d.setPresetCurrent(dto.getPresetCurrent());
        d.setPresetDuration(dto.getPresetDuration());
        d.setVoltageUpper(dto.getVoltageUpper());
        d.setVoltageLower(dto.getVoltageLower());
        d.setCurrentUpper(dto.getCurrentUpper());
        d.setCurrentLower(dto.getCurrentLower());
        d.setAgingStartTime(dto.getAgingStartTime());
        d.setAgingStopTime(dto.getAgingStopTime());
        d.setOfflineTime(dto.getOfflineTime());
        d.setErrorCode(dto.getErrorCode());

        // 计算老化时长
        // d.setAgingDuration();

        d.setStatus(Constants.Status.nameOf(dto.getStatus()));
        d.setErrorRemark(dto.getAgingErrorRemark());

        if (dto.getAgingResult() != null) {
            d.setResult((dto.getAgingResult() == 1) ? "正常" : "错误");
        }

        return d;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getErrorRemark() {
        return errorRemark;
    }

    public void setErrorRemark(String errorRemark) {
        this.errorRemark = errorRemark;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }
}
